<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->char('name', 64)->unique()->comment('昵称');
            $table->char('email', 64)->unique()->comment('邮箱');
            $table->string('password')->nullable()->comment('密码');
            $table->string('avatar')->nullable()->comment('图像');
            $table->tinyInteger('sex')->default(3)->comment('性别 1女 2男 3保密');
            $table->integer('credit')->default(0)->comment('积分');
            $table->tinyInteger('is_active')->default(0)->comment('邮箱是否验证');
            $table->string('confirm_token')->nullable()->comment('验证邮箱token');
            $table->integer('posts_count')->default(0)->comment('主题数量');
            $table->integer('comments_count')->default(0)->comment('帖子数量');
            $table->integer('follow_count')->default(0)->comment('我的关注数量');
            $table->integer('message_count')->default(0)->comment('未读消息');
            $table->timestamp('register_time')->comment('注册时间');
            $table->timestamp('login_last_time')->nullable()->comment('最后登录时间');
            $table->ipAddress('login_last_ip')->nullable()->comment('最后登录ip');
            $table->ipAddress('register_ip')->comment('注册ip');
            $table->json('setting')->nullable()->comment('其他设置');
            $table->tinyInteger('status')->default(1)->comment('用户状态 0禁用 1启用');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
